const express = require("express");
const port = 8000;
const app = express();

const students_router = require("./router/students_router");

app.use("/api", students_router);

const teachers = [
  { id: 1, name: "John", age: 18 },
  { id: 2, name: "Jane", age: 19 },
  { id: 3, name: "Bob", age: 20 },
];

// JSONP
app.get("/teachers", (req, res) => {
  res.setHeader("Content-Type", "application/json");
  res.setHeader("Access-Control-Allow-Origin", "*");
  const { callback } = req.query;
  res.send(`${callback}(${JSON.stringify(teachers)})`);
});


app.listen(port, () => {
  console.log(`服务端口开在:${port}`);
});
